package mse.eai.testes;

import java.util.Properties;

import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MessageProducer;
import javax.jms.ObjectMessage;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueSession;
import javax.jms.Session;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

public class DoTests {

	
	//startLottery_request_gw
	
	public static void main(String[] args) throws NamingException, JMSException {
		
		InitialContext context = getRemoteContext(); 
		
		//context  = new InitialContext();
		QueueConnectionFactory factory = (QueueConnectionFactory)context.lookup("ConnectionFactory");
		QueueConnection connect = factory.createQueueConnection();

		QueueSession session = connect.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

		Destination destination = (Destination)getRemoteContext().lookup("/queue/startLottery_request_gw");
		MessageProducer sender = session.createProducer(destination);

		ObjectMessage  message = session.createObjectMessage("bla");
		sender.send(message);
		connect.close();
		
	}
	
	
	public static InitialContext getRemoteContext() throws NamingException {
	    Properties env = new Properties();
	    env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory" );
	    env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
	    env.put(Context.PROVIDER_URL, "jnp://localhost:1099");
	    return new InitialContext(env);
	}
}
